package cn.com.chengmandian.bike.controller;

import cn.com.chengmandian.bike.service.IEbPreOrderService;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.service.bike.form.PreOrderCancelForm;
import cn.com.chengmandian.service.bike.form.PreOrderMoneyModifyForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "预支付 - 微服务")
@RestController
@RequestMapping("/inner/pre")
public class InnerPreController {
    @Autowired
    private IEbPreOrderService preOrderService;

    @ApiOperation("取消预支付订单")
    @PostMapping("/order/cancel")
    public AjaxResult cancelOrder(@RequestBody PreOrderCancelForm form) {
        Assert.notNull(form.getPreOrderId(), "请传入订单ID");
        preOrderService.cancelOrderById(form.getPreOrderId());
        return AjaxResult.success();
    }

    @ApiOperation("修改支付分扣款金额（根据骑行订单ID）")
    @PostMapping("/order/money/modify")
    public AjaxResult modifyOrderMoney(@RequestBody PreOrderMoneyModifyForm form) throws Exception {
        Assert.notNull(form.getRideOrderId(), "请传入骑行订单ID");
        preOrderService.updateOrderMoneyByRideId(form.getRideOrderId());
        return AjaxResult.success();
    }
}
